<?php echo $this->Html->script("ZeroClipboard"); ?>
<?php echo $this->Html->script("TableTools"); ?>
<div id="content">
	<!--  start page-heading -->
	<div id="page-heading">
		<h1>Customers Report</h1>
	</div>
	<!-- end page-heading -->
	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tr>
		<th rowspan="3" class="sized">
        <?php echo $this->Html->image('/images/shared/side_shadowleft.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
    </th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized">
        <?php echo $this->Html->image('/images/shared/side_shadowright.jpg', array('width' => '20', 'height' => '300', 'alt' => '')); ?>
    </th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td>
		<!--  start content-table-inner ...................................................................... START -->
		
			<!--  start table-content  -->

		<div id="content-table-inner">
        <div id="filter" style="width: 217px; position: relative;display: none;">
                <select name="select-report" id="select-report">
                    <option value=""> Select Customer Report Type </option>
                    <option value="weekly">Weekly</option>
                    <option value="monthly">Monthly</option>
                    <option value="yearly">Yearly</option>
                </select>
        </div>
				<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
				  <thead>	
            <tr>
    					<th class="table-header-repeat line-left minwidth-1">
                   <?php echo __('Name'); ?>
              </th>
    					<th class="table-header-repeat line-left minwidth-1">
                   <?php echo __('Email'); ?>
              </th>
    					<th class="table-header-repeat line-left minwidth-1">
                   <?php echo __('Username'); ?>
              </th>
    					<th class="table-header-repeat line-left minwidth-1">
                   <?php echo __('Balance'); ?>
              </th>
    					<th class="table-header-repeat line-left">
                   <?php echo __('Mobile'); ?>
              </th>
    					<th class="table-header-repeat line-left">
                   <?php echo __('Customer Type'); ?>
              </th>          
    					<th class="table-header-repeat line-left">
                   <?php echo __('Birthday'); ?>
              </th>          
    					<th class="table-header-repeat line-left">
                   <?php echo __('Country'); ?>
              </th>          
    					<th class="table-header-repeat line-left">
                   <?php echo __('City'); ?>
              </th>          
    					<th class="table-header-repeat line-left">
                   <?php echo __('date'); ?>
              </th>          
    				</tr>
          </thead>
          <tbody>	
        <?php foreach ($customers as $customer): ?>
            <tr>
                <td><?php echo $customer['Customer']['f_name'].' '.$customer['Customer']['l_name']; ?></td>
                <td>
                    <?php echo $customer['Customer']['email']; ?>
                </td>
                <td>
                    <?php echo $customer['Customer']['username']; ?>
                </td>
                <td>
                    <?php echo $customer['Customer']['balance']; ?>
                </td>
                <td>
                    <?php echo $customer['Customer']['mobile']; ?>
                </td>
                <td>
                    <?php echo $customer['CustomerType']['name']; ?>
                </td>
                <td>
                    <?php echo $customer['Customer']['birthday']; ?>
                </td>
                <td>
                    <?php echo $customer['Country']['name']; ?>
                </td>
                <td>
                    <?php echo $customer['City']['name']; ?>
                </td>
                <td>
                    <?php echo date('Y-m-d', strtotime($customer['Customer']['created'])); ?>
                </td>
            </tr>
        <?php endforeach; ?>
          </tbody>
        </table>
			<div class="clear"></div>

		</div>
	 
			  <?php //echo $this->element("Tickets".'/listing'); ?>
      <!--  end content-table  -->
		<!--  end content-table-inner ............................................END  -->
		</td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>

</div>
	
<script type="text/javascript">

  jQuery("document").ready(function(){
      jQuery("#select-report").live('change', function(){
          var selected = jQuery(this).val();
            jQuery.ajax({
                    type: "POST",
                    url: "<?php echo $this->Html->url(array('controller'=>'reports','action'=>'customer_filter')); ?>/"+selected,
                    success: function(msg){
                        jQuery("#content-table-inner").html(msg);
                        jQuery("#select-report option[value= '"+selected+"']").attr('selected', 'selected');
                    }
             })
      });   
  });
  
jQuery(document).ready( function () {
   date = "<?php echo date('M-d g i A') ?>";
  jQuery('#product-table').dataTable( {
        "bDestroy" : true,
        "bJQueryUI": true,
        "bSort": false,
        "oLanguage": {
            "sInfo": "_START_ - _END_ of _TOTAL_",
            "oPaginate": {
              
              "sFirst": " ",
              "sPrevious": " ",
              "sNext": " ",
              "sLast": " "
            }
        },
        "sPaginationType": "full_numbers",
        "bLengthChange": false,
        "bFilter": true,
        "sDom": '<"H"Tfr>t<"F"ip>',
        "oTableTools": {
          "aButtons": [
                 {
                    "sExtends": "xls",
                    "sFileName": "Loyalty_Customers-Report "+date+".xls"
                },
                 {
                    "sExtends": "pdf",
                    "sTitle": "Customers Report "+date+".",
                    "sFileName": "Loyalty_Customers-Report "+date+".pdf"
                }
          ],
           "sSwfPath": "<?php echo $this->webroot; ?>app/webroot/media/swf/copy_csv_xls_pdf.swf"
        },
      "fnDrawCallback": function (oSettings) {
          currentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength);
          totalPages = Math.ceil(oSettings.fnRecordsDisplay() / oSettings._iDisplayLength);
          currentPage += 1;
          jQuery('#report-table_info').html('Page ' + currentPage + ' of ' + totalPages )
      }
    } );
   val = jQuery('#filter').html();
  jQuery('#product-table_filter').after(val);
});
</script>
